package net.onceface.core.domain;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import net.onceface.core.domain.mappedsuper.TimeIntervalEntity;

/**
 * 优惠规则
 * **/
@Entity
@Table(name = "SYS_DISCOUNTS")
public class DisCount extends TimeIntervalEntity{

	/**
	 * 
	 */
	private static final long serialVersionUID = 8651268117544642212L;

	/**
	 * 优惠门槛
	 * **/
	@Column(name = "THRESHOLD")
	private double threshold; 
	
	/**
	 * 优惠标题
	 * **/
	@Column(name = "TITLE")
	private String title;
	
	/**
	 * 优惠类型
	 * 1.满**减** 2.满**加**换** 3.满**送**券   4.满**件**折
	 * **/
	@Column(name = "TYPE")
	private int type;
	
	/**
	 * 优惠类型，类型1相减，类型2相加，类型4时相乘
	 * **/
	@Column(name = "DISCOUNT")
	private double disCount; 
	
	/**
	 * 优惠券ID 优惠类型3时送此券
	 * **/
	@Column(name = "COUPON_ID")
	private Long couponId;
	
	/**
	 * 商品列表
	 * 优惠类型为2是可换的商品
	 * **/
	@ManyToMany(fetch=FetchType.LAZY)
	@JoinTable(name = "SYS_DISCOUNT_RELATION",
			joinColumns = @JoinColumn(name = "DISCOUNT_ID"),
			inverseJoinColumns = @JoinColumn(name = "PRODUCT_ID"))
	private Set<Product> products;
	
	/**
	 * 是否有效
	 * **/
	@Column(name = "VALID")
	private boolean valid;

	public double getThreshold() {
		return threshold;
	}

	public void setThreshold(double threshold) {
		this.threshold = threshold;
	}

	public Long getCouponId() {
		return couponId;
	}

	public void setCouponId(Long couponId) {
		this.couponId = couponId;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public double getDisCount() {
		return disCount;
	}

	public void setDisCount(double disCount) {
		this.disCount = disCount;
	}

	public Set<Product> getProducts() {
		return products;
	}

	public void setProducts(Set<Product> products) {
		this.products = products;
	}

	public boolean isValid() {
		return valid;
	}

	public void setValid(boolean valid) {
		this.valid = valid;
	}

	@Override
	public String[] businessKeys() {
		// TODO Auto-generated method stub
		return null;
	}

	
}
